package com.example.backend.controller;


import com.example.backend.Assistant.RestaurantChatAssistant;
import com.example.backend.pojo.ChatForm;
import com.example.backend.pojo.DTO.ChatSessionDTO;
import com.example.backend.pojo.DTO.UserChatSessionSummaryDTO;
import com.example.backend.service.ChatMessagesService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;


@Tag(name = "医疗机器人")
@RestController
@RequestMapping("/res")
public class ResController {

    @Autowired
    private RestaurantChatAssistant assistant;

    @PostMapping(value = "/chat", produces = "text/stream;charset=utf-8")
    public Flux<String> chat(@RequestBody ChatForm chatForm) {
        System.out.println("用户输入：" + chatForm.getMessage());
        return assistant.chat(chatForm.getMemoryId(), chatForm.getMessage());
    }


    @Autowired
    private ChatMessagesService chatMessagesService;

    // 查询用户的所有聊天记录
        @GetMapping("/user")
    public List<UserChatSessionSummaryDTO>  getUserChatRecords() {
        return chatMessagesService.findAllByUserId();
    }

    // 查询特定会话的所有记录
    @GetMapping("/memory/{memoryId}")
    public ChatSessionDTO getMemoryChatRecords(@PathVariable("memoryId") String memoryId) {

        return chatMessagesService.findAllByMemoryId(memoryId);
    }


}
